from datetime import datetime
from decimal import Decimal
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from module_admin.annotation.pydantic_annotation import as_query


class SettlementModel(BaseModel):
    """
    交易交割记录表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='主键ID')
    account_no: Optional[str] = Field(default=None, description='所属证券账号')
    trade_date: Optional[datetime] = Field(default=None, description='成交日期')
    trade_time: Optional[str] = Field(default=None, description='成交时间')
    stock_code: Optional[str] = Field(default=None, description='证券代码')
    stock_name: Optional[str] = Field(default=None, description='证券名称')
    operation: Optional[str] = Field(default=None, description='操作')
    trade_quantity: Optional[Decimal] = Field(default=None, description='成交数量')
    trade_no: Optional[str] = Field(default=None, description='成交编号')
    average_price: Optional[Decimal] = Field(default=None, description='成交均价')
    trade_amount: Optional[Decimal] = Field(default=None, description='成交金额')
    balance: Optional[Decimal] = Field(default=None, description='余额')
    occurred_amount: Optional[Decimal] = Field(default=None, description='发生金额')
    commission: Optional[Decimal] = Field(default=None, description='手续费')
    stamp_duty: Optional[Decimal] = Field(default=None, description='印花税')
    other_fees: Optional[Decimal] = Field(default=None, description='其他杂费')
    current_amount: Optional[Decimal] = Field(default=None, description='本次金额')
    contract_no: Optional[str] = Field(default=None, description='合同编号')
    regulatory_fee: Optional[Decimal] = Field(default=None, description='证管费')
    handling_fee: Optional[Decimal] = Field(default=None, description='经手费')
    other_charges: Optional[Decimal] = Field(default=None, description='其他费用')
    exchange: Optional[str] = Field(default=None, description='交易市场')
    total_fees: Optional[Decimal] = Field(default=None, description='费用合计')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')


class SettlementQueryModel(SettlementModel):
    """
    交易交割记录不分页查询模型
    """
    begin_trade_date: Optional[str] = Field(default=None, description='开始成交日期')
    end_trade_date: Optional[str] = Field(default=None, description='结束成交日期')
    account_nos: Optional[str] = Field(default=None, description='所属证券账号列表')
    account_no_list: Optional[list] = Field(default=None, description='所属证券账号列表')
    operation_list: Optional[list] = Field(default=None, description='操作列表')


@as_query
class SettlementPageQueryModel(SettlementQueryModel):
    """
    交易交割记录分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteSettlementModel(BaseModel):
    """
    删除交易交割记录模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    ids: str = Field(description='需要删除的主键ID')


class GenerateStatModel(BaseModel):
    """
    生成统计模型
    """

    start_date: Optional[str] = Field(default=None, description='开始日期，格式为 YYYY-MM-DD')
